<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    const imgUrl = 'https://img1.baidu.com/it/u=2402758734,4069351267&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=214'
    const imgPromise = (url) => {
      return new Promise((resolve, reject) => {
        const img = new Image()
        img.src = url
        img.onload = () => {
          resolve(img)
        }
        img.onerror = () => {
          reject(new Error('图片有误'))
        }
      })
    }
    imgPromise(imgUrl)
      .then(img => document.body.appendChild(img))
      .catch(err => document.body.innerHTML = err)


  </script>
</body>

</html>